package com.market.plus.core.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

@Entity
@Table(name = "AlBUM")
@NamedQueries( { 
   @NamedQuery(name = Album.FIND_ALL, query = "SELECT album FROM Album album"),
   @NamedQuery(name = Album.FIND_BY_NAME, query = "SELECT album FROM Album album where LOWER(album.name)=LOWER(:name) and album.participant.id=:participantId"),
   @NamedQuery(name = Album.FIND_BY_TYPE, query = "SELECT album FROM Album album where album.albumType=:albumType and album.participant.id=:participantId")})
public class Album implements Persistable, StatusInfo, ModifyedInfo {

   public static final String FIND_ALL = "AlBUM.FIND_ALL";

   public static final String FIND_BY_NAME = "AlBUM.FIND_BY_NAME";

   public static final String FIND_BY_TYPE = "AlBUM.FIND_BY_TYPE";

   public static final String PARA_NAME = "name";

   public static final String PARA_TYPE = "albumType";

   public static final String PARA_PARTICIPANTID = "participantId";
   
   @Id
   @GeneratedValue(strategy = GenerationType.TABLE, generator = "GEN_AlBUM")
   @TableGenerator(name = "GEN_AlBUM", table = "SEQUENCE_LIST", allocationSize = 1, initialValue = 1, pkColumnName = "NAME", valueColumnName = "NEXT_SEQUENCE", pkColumnValue = "AlBUM")
   @Column(name = "AlBUM_ID")
   private Long id;

   @Column(name = "AlBUM_NAME", nullable = false)
   private String name;

   @Column(name = "AlBUM_GUID", unique = true, nullable = false)
   private String albumGUID;

   @Column(name = "ALBUM_TYPE")
   @Enumerated(EnumType.ORDINAL)
   private AlbumType albumType;

   @Column(name = "DESCRIPTION")
   private String description;

   @ManyToOne
   @JoinColumn(name = "PARTICIPANT_ID")
   private Participant participant;

   @Column(name = "CREATED_USER")
   private String createdUser;

   @Column(name = "CREATED_DATE")
   private Date createdDate;

   @Column(name = "MODIFYED_USER")
   private String modifyedUser;

   @Column(name = "MODIFYED_DATE")
   private Date modifyedDate;

   @Column(name = "STATUS")
   @Enumerated(EnumType.ORDINAL)
   private Status status;

   public Album() {
      
   }

   public Long getId() {
      return id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public Status getStatus() {
      return status;
   }

   public void setStatus(Status status) {
      this.status = status;
   }

   public String getCreatedUser() {
      return createdUser;
   }

   public void setCreatedUser(String createdUser) {
      this.createdUser = createdUser;
   }

   public Date getCreatedDate() {
      return createdDate;
   }

   public void setCreatedDate(Date createdDate) {
      this.createdDate = createdDate;
   }

   public String getModifyedUser() {
      return modifyedUser;
   }

   public void setModifyedUser(String modifyedUser) {
      this.modifyedUser = modifyedUser;
   }

   public Date getModifyedDate() {
      return modifyedDate;
   }

   public void setModifyedDate(Date modifyedDate) {
      this.modifyedDate = modifyedDate;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public Participant getParticipant() {
      return participant;
   }

   public void setParticipant(Participant participant) {
      this.participant = participant;
   }

   public String getAlbumGUID() {
      return albumGUID;
   }

   public void setAlbumGUID(String albumGUID) {
      this.albumGUID = albumGUID;
   }

   public AlbumType getAlbumType() {
      return albumType;
   }

   public void setAlbumType(AlbumType albumType) {
      this.albumType = albumType;
   }

   public String getDescription() {
      return description;
   }

   public void setDescription(String description) {
      this.description = description;
   }

   @Override
   public boolean equals(Object obj) {
      Album propertyCompare = (Album) obj;
      if (this.getId().longValue() == propertyCompare.getId().longValue()) {
         return true;
      }
      return false;
   }
}
